<template>
    <div class="bag">
        <div class="tabs-container">
            <button class="cssbuttons-io-button" :class="{active: tabButton === 'CURRENT'}" @click="switchTab('CURRENT')">
                <span>现货</span>
            </button>
            <button class="cssbuttons-io-button" :class="{active: tabButton === 'PRESALE'}" @click="switchTab('PRESALE')">
                <span>空气谷</span>
            </button>
            <!-- <div class="tab-button" :class="{ active: tabButton === 'current' }" @click="switchTab('current')">现货</div>
            <div class="tab-button" :class="{ active: tabButton === 'air' }" @click="switchTab('air')">空气谷</div> -->
        </div>

        <van-grid :column-num="2" :gutter="10">
            <van-grid-item v-for="item in items" :key="item.id">
                <div class="item-card">
                    <img :src="item.image" class="item-image" />
                    <div class="item-info">
                        <div class="item-name">{{ item.name }}</div>
                    </div>
                </div>
            </van-grid-item>
        </van-grid>
    </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { http } from '@/utils/request'
const tabButton = ref('CURRENT')

const switchTab = (tab) => {
    tabButton.value = tab
    getList()
}

// 模拟数据
const items = ref([])

const getList = () => {
    http.post('/goods/page', {
        current: 1,
        pageSize: 10,
        queryCondition: {
            isPresale: tabButton.value
        }
    }).then((res) => {
        items.value = res.records
    })
}

onMounted(() => {
    getList()
})
</script>

<style lang="scss" scoped>
.bag {
    width: 100%;
    height: 100%;
    padding: 16px;
    background-color: #f5f5f5;
    overflow: auto;
}

.tabs-container {
    display: flex;
    // justify-content: space-between;
    gap: 20px;
    margin-bottom: 16px;
}

.tab-button {
    width: 48%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    background-color: #ffffff;
    border-radius: 4px;
    font-size: 16px;
    color: #333333;
    cursor: pointer;

    &.active {
        // 渐变#edf4e5
        background: linear-gradient(to right, #e9bf47, #f4f9ef);
        color: #4a6741;
    }
}

:deep(.van-grid-item__content) {
    background-color: initial;
    padding: 0;
}

.item-card {
    width: 100%;
    padding: 8px;
    background-color: #fff;
    border-radius: 8px;
}

.item-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
}

.item-info {
    padding: 8px 0;
}

.item-name {
    font-size: 14px;
    color: #323233;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-price {
    font-size: 16px;
    color: #f44;
    font-weight: bold;
    margin-top: 4px;
}
</style>

<style lang="scss" scoped>
.cssbuttons-io-button {
  display: flex;
  align-items: center;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  font-size: 17px;
  padding: 0.8em 1.5em 0.8em 1.5em;
  border: 1px solid #4d36d0;
  color: #4d36d0;
  box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
  letter-spacing: 0.05em;
  border-radius: 20em;

  &.active {
    background: #ad5389;
    background: linear-gradient(
    0deg,
    rgba(77, 54, 208, 1) 0%,
    rgba(132, 116, 254, 1) 100%
    );
    color: #fff;
  }
}

.cssbuttons-io-button svg {
  margin-right: 8px;
}

.cssbuttons-io-button:hover {
  box-shadow: 0 0.5em 1.5em -0.5em #4d36d0be;
}

.cssbuttons-io-button:active {
  box-shadow: 0 0.3em 1em -0.5em #4d36d0be;
}

</style>